﻿using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace SceneUnpacker.se.gno
{
    public class CommandLine
    {
        private List<string> Arguments = new List<string>();
        private Dictionary<string, Option> Options = new Dictionary<string, Option>();

        public CommandLine(string[] Args)
        {
            Regex regex = new Regex("^-{1,2}|^/", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            new Regex("^['\"]?(.*?)['\"]?$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            foreach (string str in Args)
            {
                if (!regex.IsMatch(str))
                {
                    this.Arguments.Add(str);
                }
            }
        }

        internal void AddOption(Option option)
        {
            this.Options.Add(option.Name, option);
        }

        public Option this[string Param]
        {
            get
            {
                return this.Options[Param];
            }
        }

        public string this[int Index]
        {
            get
            {
                if (Index >= this.Arguments.Count)
                {
                    return null;
                }
                return this.Arguments[Index];
            }
        }

        public class Option
        {
            private bool _hasValue;
            private string _name;
            private string _value;

            public Option(string name, bool hasValue)
            {
                this._name = name;
                this._hasValue = hasValue;
            }

            public bool HasValue
            {
                get
                {
                    return this._hasValue;
                }
            }

            public string Name
            {
                get
                {
                    return this._name;
                }
            }

            public string Value
            {
                get
                {
                    return this._value;
                }
                set
                {
                    this._value = value;
                }
            }
        }
    }
}

